﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Portal.Presentation.Models;
using Portal.Presentation.Tests.Units;
using Rhino.Mocks;
using FluentValidation;
using FluentAssertions;

namespace Portal.Presentation.Validators.Tests.Units
{
	[TestClass()]
	public class UserInfoDataModelValidatorTests : BaseTests
	{
		protected override void InitializeTest()
		{
		}

		#region Validate

		[TestMethod]
		public void Validate_UserInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);
			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_UserLastNameHasMoreThan50Chars_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "over 50 chars       123456789 123456789 123456789 1",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_UserFirstNameHasMoreThan50Chars_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "over 50 chars       123456789 123456789 123456789 1",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_FirstNameIsEmpty_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_LastNameIsEmpty_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_PimaryPhoneIsEmpty_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = ""
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(2);
		}

		[TestMethod]
		public void Validate_PrimaryEmailIsEmpty_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(2);
		}

		[TestMethod]
		public void Validate_PrimaryMobilePhoneIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_PrimaryStationaryPhoneIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "22 842 33 33"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_PrimaryPhoneIsNotValid_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999#000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_SecondaryMobilePhoneIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999",
				SecondaryPhone = "999 000 999"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_SecondaryStationaryPhoneIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "22 842 33 33",
				SecondaryPhone = "22 842 33 33"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_SecondaryPhoneIsNotValid_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999",
				SecondaryPhone = "22#333 333"
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_PrimaryEmailInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999",
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_PrimaryEmailInfoIsNotValid_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa#aaa",
				PrimaryPhone = "999 000 999",
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_SecondaryEmailInfoIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa.aaa",
				SecondaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999",
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_SecondaryEmailInfoIsNotValid_ResultIsNotValid()
		{
			var validator = GetValidator();
			var model = new UserInfoDataModel()
			{
				LastName = "last name",
				FirstName = "first name",
				PrimaryEmail = "aaa@aaa#aaa",
				SecondaryEmail = "aaa@aaa.aaa",
				PrimaryPhone = "999 000 999",
			};

			var result = validator.Validate(model);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		#endregion Validate

		private UserInfoDataModelValidator GetValidator()
		{
			return new UserInfoDataModelValidator();
		}
	}
}